import { Component, OnInit, ViewChild } from '@angular/core';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from '@core/services/api';
import {HttpClient} from "@angular/common/http";
import { PermissionService } from '@core/services/permission.service';
import { ACLService } from '@delon/acl';
import { STData } from '@delon/abc';
import { CostAddComponent } from '../cost-add/cost-add.component';
import { PayMoneyComponent } from '../pay-money/pay-money.component';
import { OneOpenAllComponent } from '../one-open-all/one-open-all.component';

@Component({
  selector: 'app-cost-list',
  templateUrl: './cost-list.component.html',
  styles: []
})
export class CostListComponent implements OnInit {
  @ViewChild('st', {static: false})st: TablePageComponent;
  config: SPage = {
    columns: [
      {
        index: 'areaShortName',
        title: '小区',
        filter: {
          type: 'string'
        }
      },
      {
        index: 'areaName',
        title: '地址',
      },
      {
        index: 'houseCount',
        title: '楼栋数量',
        fFn: (item, cloumn): string => {
          return item.areaDataCount.houseCount+''
        },
      },
      {
        index: 'hostCount',
        title: '单元数量',
        fFn: (item, cloumn): string => {
          return item.areaDataCount.hostCount+''
        },
      },
      {
        index: 'roomCount',
        title: '房间数量',
        fFn: (item, cloumn): string => {
          return item.areaDataCount.roomCount+''
        },
      },
      {
        index: '',
        title: '操作',
        buttons:[
          {
            text:'费用设置',
            click:(_record)=>{
              this.editDic(_record)
            }
          },
          {
            text:'缴费',
            click:(_record)=>{
              this.payMoney(_record)
            }
          },
          {
            text:'一键开通',
            click:(_record)=>{
              this.openAll(_record)
            }
          },
        ]
      },
    ],
    reqUrl: "/core/qr/pay/findAreaItem",
  };
  selectedData: object[];
  //数据预处理
  dataProcess(data: STData[]){
    return data;
  }

  editDic(_param?: object): void {
    this.modal.create({
      nzTitle: "费用设置",
      nzContent: CostAddComponent,
      nzWidth: 1200,
      nzComponentParams: {
        _param
      },
      nzOnOk: () => {
        // this.st.reload();
      },
      nzFooter: null
    })
  }
  payMoney(_param?:object):void{
    this.modal.create({
      nzTitle: "缴费",
      nzContent: PayMoneyComponent,
      nzWidth: 1200,
      nzComponentParams: {
        _param
      },
      nzOnOk: () => {
        this.st.reload();
      },
      nzFooter: null
    })
  }
  openAll(_param?:object):void{
    this.modal.create({
      nzTitle: "一键开通",
      nzContent: OneOpenAllComponent,
      nzWidth: 1200,
      nzComponentParams: {
        _param
      },
      nzOnOk: () => {
        this.st.reload();
      },
      nzFooter: null
    })
  }
  _selectChange(e): void {
    this.selectedData = e;
  }

  selectChange(event): void {
    this.st.searchData({areaParentId: event.keys[0]});
  }

 
  constructor(
    private modal: NzModalService,
    private msg: NzMessageService,
    private api: ApiService,
    private http: HttpClient,
    private permission: PermissionService,
    private aclService: ACLService
  ) { }


  ngOnInit() {
  
  }

}
